package com.common.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.subject.Subject;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by dell on 2016/11/9.
 */
@RestController
@RequestMapping("common")
public class CommonController {

    @RequestMapping(method = RequestMethod.GET)
    @RequiresAuthentication
    public String get(){
        return "hello common";
    }

    @RequestMapping(value = "login",method = RequestMethod.GET)
    public String login(String name,String password){
        UsernamePasswordToken token=new UsernamePasswordToken(name,password);
        Subject subject= SecurityUtils.getSubject();
        subject.login(token);
        return "login success";
    }
}
